package lego.jbv;

import java.util.Random;

import lejos.nxt.LCD;
import lejos.robotics.subsumption.Behavior;
import lejos.util.Delay;

public class Wander implements Behavior{

	private boolean _suppressed = false;
	private Random random = new Random();
	private final int minSpeed = 50;
	private final int maxSpeedAddition = 5; //This means the max speed is 100. 
	private Car car;
	public Wander(Car _car)
	{
		car = _car;
	}
	@Override
	public boolean takeControl() {
		return true;
	}

	@Override
	public void action() {
		_suppressed = false;
		long time = System.currentTimeMillis();
		
		while (!_suppressed) {
			//Random driving
			car.drive(minSpeed + (random.nextInt(maxSpeedAddition)*10), minSpeed + (random.nextInt(maxSpeedAddition)*10), true);
			
			LCD.drawInt(random.nextInt(maxSpeedAddition), 2, 0, 3);
			
			while((System.currentTimeMillis() - time) < 500)
			{
				Thread.yield();
			}
		}
	}

	@Override
	public void suppress() {
		_suppressed = true;
	}
}